package cn.net.xyan.yypt.demo

import cn.net.xyan.blossom.kotlin.DateExt
import cn.net.xyan.blossom.kotlin.javaType
import cn.net.xyan.blossom.kotlin.json
import cn.net.xyan.blossom.kotlin.parametricType
import cn.net.xyan.yypt.dto.protal.LKAlipayCheck
import cn.net.xyan.yypt.dto.protal.LKAlipayEmptyBodyReq
import cn.net.xyan.yypt.dto.protal.LKAlipayRefund
import cn.net.xyan.yypt.service.PayOrderService
import com.fasterxml.jackson.dataformat.xml.XmlMapper
import java.net.URL
import java.text.SimpleDateFormat

fun main(array: Array<String>) {

    //val BaseURL = "http://yypt.xyan.net.cn:18002/ydpt/public/qrCode?value="

    val df = SimpleDateFormat("yyyyMMddHHmmssSSS")

    val xmlMapper = XmlMapper()

    println(xmlMapper.writeValueAsString("abc"))

    val url = URL("http://yypt.xyan.net.cn:18002/ydpt/public/cxf/pay?wsdl")

    // val url = URL("http://127.0.0.1:8080/public/cxf/pay?wsdl")

    val service: PayOrderService = createInstance(url, PayOrderService::class.java)


    val qrRefund = LKAlipayRefund()

    qrRefund.outRequestNo = df.format(DateExt.now)

    qrRefund.tradeNo = "20180125133025463"
    qrRefund.refundAmount = "0.01"

    qrRefund.refundmentReason = "测试"


    val req = LKAlipayEmptyBodyReq<LKAlipayRefund>()

    println(qrRefund.json)

    req.head = qrRefund


    val rsp = service.refund(xmlMapper.writeValueAsString(req))


    println(rsp)

    val rspObj: Map<String, Any?> =
            xmlMapper.readValue(rsp, Map::class.parametricType(String::class.javaType, Any::class.javaType))

    val qrQuery = LKAlipayCheck()

    println(rspObj)

    qrQuery.outTradeNo = qrRefund.tradeNo


    val req2 = LKAlipayEmptyBodyReq<LKAlipayCheck>()

    println(qrQuery.json)

    req2.head = qrQuery

    val rsp2 =  service.query(xmlMapper.writeValueAsString(req2))

    println(rsp2)




}
